home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 1.8 KB | 60 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import quicktime.*;
- import quicktime.std.music.*;
- import quicktime.std.StdQTException;
- import quicktime.util.QTUtils;
-
- public class NotesToneTest implements Errors {
- public static void main (String[] args) {
- try {
- System.out.println ("Starting QTMA Test");
- QTSession.open();
-
- // A NoteAllocator is required for using NoteChannels
- // However QTJava provides a default NA:
- // NoteAllocator na = NoteAllocator.getDefault();
- // and this is used for the TD/NR and NC constructors if the
- // application does not provide one.
-
- System.out.println ("Pick Instrument:");
- ToneDescription td = new ToneDescription ();
- //print out an uninitialized ToneDescription
- System.out.println (td);
-
- try {
- // Have the user choose an instrument and print out the choice
- td.pickInstrument (NoteAllocator.getDefault(), "Choose an Instrument...", 0);
- System.out.println (td);
- } catch (StdQTException e) {
- if (e.errorCode() != userCanceledErr) return;
- }
-
- // Make a Tone Description using GMIDI inst. no. 25
- System.out.println ("StuffTone:25");
- td = new ToneDescription (25);
- System.out.println (td);
-
- // Play a note (60) at maximum velocity (127) for 2000msecs then turn it off.
- System.out.println ("PlayNote:Inst,25, Note,60");
- NoteChannel nc = new NoteChannel(new NoteRequest(td));
- nc.playNote (60, 127);
- try { Thread.sleep (2000); }
- catch (InterruptedException e) { e.printStackTrace(); }
- nc.playNote (60, 0);
- }
- catch (QTException qte) {
- qte.printStackTrace();
- }
- finally {
- System.out.println ("Finished QTMA Test");
- QTSession.close();
- }
- }
- }
-